package com.backend.system.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 时间范围
 *
 * @author backend-manage
 */
@ApiModel
@Data
public class TimeRange implements Serializable {
    @Serial
    private static final long serialVersionUID = -4908251614987606054L;

    @ApiModelProperty("起始时间")
    private LocalDateTime start;

    @ApiModelProperty("结束时间")
    private LocalDateTime end;


    public void valid() {

        // 起止时间可以同时为空
        if (start == null && end == null) {
            return;
        }

        if (start != null && end != null) {
            if (start.isBefore(end)) {
                return;
            }
        }

        throw new CustomException("时间范围选择错误");
    }
}
